package com.qdlc.p2p.biz.borrowworker.worker;

import java.util.Date;
import java.util.List;

import com.qdlc.p2p.dal.dto.Account;
import com.qdlc.p2p.dal.dto.Borrow;
import com.qdlc.p2p.dal.dto.BorrowCollection;
import com.qdlc.p2p.dal.dto.BorrowConfig;
import com.qdlc.p2p.dal.dto.BorrowRepayment;
import com.qdlc.p2p.dal.dto.BorrowTender;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.dto.UserCache;
import com.qdlc.p2p.dal.model.BorrowModel;
import com.qdlc.p2p.dal.model.interest.InterestCalculator;

/**
 * 封装Borrow业务处理接口
 * 
 * @author Administrator
 */
public interface BorrowWorker {

	/**
	 * @return
	 */
	Borrow prototype();

	/**
	 * @return
	 */
	BorrowConfig getBorrowConfig();

	/**
	 * @param user
	 */
	void setBorrowField(User user);

	/**
	 * 是否跳过初审
	 * 
	 * @param borrow
	 */
	void skipTrial(Borrow borrow);

	/**
	 * 
	 */
	void trial();

	/**
	 * 初审
	 */
	void verify();

	/**
	 * 撤回
	 */
	void revokeBorrow();
	
	/**
	 * 秒标初审不通过解冻资金
	 */
	void secondUnVerifyFreeze();
	
	/**
	 * 还款处理
	 */
	BorrowRepayment repay(BorrowModel model);

	/**
	 * 截标
	 */
	void stopBorrow();

	/**
	 * 是否跳过满表复审
	 */
	void skipReview();

	/**
	 * 计算借款标的利息
	 * 
	 * @return
	 */
	double calculateInterest();

	/**
	 * 计算借款标的利息
	 * 
	 * @return
	 */
	double calculateInterest(double validAccount);

	/**
	 * @return
	 */
	InterestCalculator interestCalculator();

	/**体验标利息
	 * @param validAccount
	 * @param date 
	 * @return
	 */
	InterestCalculator exInterestCalculator(double validAccount, Date date);
	
	/**
	 * @param validAccount
	 * @return
	 */
	InterestCalculator interestCalculator(double validAccount);

	/**
	 * 计算借款标的手续费
	 * 
	 * @return
	 */
	double calculateBorrowFee();

	/**
	 * @return
	 */
	double calculateBorrowAward();

	/**
	 * @return
	 */
	BorrowRepayment[] getRepayment();

	/**
	 * @param period
	 * @return
	 */
	Date getRepayTime(int period);

	/**
	 * 获取还款日期
	 * @param period
	 * @param borrowModel
	 */
	Date getRepayTime(int period, BorrowModel borrowModel);

	/**
	 * @param period
	 * @return
	 */
	Date getFlowRepayTime(int period);

	/**
	 * 获取流标还款日期
	 * @param period
	 * @param borrowModel
	 */
	Date getFlowRepayTime(int period, BorrowModel borrowModel);

	/**
	 * @return
	 */
	boolean isNeedRealName();

	/**
	 * @return
	 */
	boolean isNeedVIP();

	/**
	 * @return
	 */
	boolean isNeedEmail();

	/**
	 * @return
	 */
	boolean isNeedPhone();

	/**
	 * @return
	 */
	boolean isNeedVideo();

	/**
	 * @return
	 */
	boolean isNeedScene();

	/**
	 * @param u
	 * @return
	 */
	boolean checkIdentify(User u);

	/**
	 * @return
	 */
	boolean checkModelData();

	/**
	 * 是否最后一期
	 * 
	 * @param period 期数
	 * @return
	 */
	boolean isLastPeriod(int period);

	/**
	 * @return
	 */
	double getTransactionFee();

	/**
	 * @param tender
	 * @param ic
	 * @return
	 */
	List<BorrowCollection> createCollectionList(BorrowTender tender, InterestCalculator ic);

	/**
	 * @param tender
	 * @param period
	 * @return
	 */
	String calCollectionRepayTime(BorrowTender tender, int period);

	/**
	 * @param clist
	 * @return
	 */
	List<BorrowRepayment> createFlowRepaymentList(List<BorrowCollection> clist);

	/**
	 * 计算奖励情况
	 * 
	 * @return
	 */
	double calculateAward();

	/**
	 * @param account
	 * @return
	 */
	double calculateAward(double account);

	/**
	 * 投标奖励
	 * @param account
	 * @param borrow
	 * @return
	 */
	double calculateAward(double account, Borrow borrow);

	/**
	 * @return
	 */
	boolean allowFullSuccess();


	/**
	 * @param tender
	 * @param m
	 * @return
	 */
	double validAccount(BorrowTender tender, BorrowModel m);

	/**
	 * @param user
	 * @return
	 */
	boolean allowPublish(User user);

	/**
	 * 发标前处理
	 * 
	 * @param borrow
	 * @return
	 */
	Borrow handleBorrowBeforePublish(Borrow borrow);

	/**
	 * 发标后处理
	 * 
	 * @param borrow
	 * @return
	 */
	Borrow handleBorrowAfterPublish(Borrow borrow);

	/**
	 * 投标前校验
	 * 
	 * @param model
	 * @param tenderNum
	 * @param user
	 * @param flow_count
	 * @return
	 */
	BorrowModel checkTenderBefore(BorrowModel model, double tenderNum, User user, int flow_count);

	/**
	 * 投标校验
	 * 
	 * @param tender
	 */
	void checkTender(BorrowTender tender);
	
	/**
	 * 投标校验
	 * @param model
	 * @param sessionUser
	 * @param userCache 
	 */
	void checkTender(BorrowModel model, User sessionUser, UserCache userCache );


	/**
	 * @param tender
	 * @param ic
	 * @return
	 */
	BorrowTender tenderSuccess(BorrowTender tender, InterestCalculator ic);
	
	/**体验标用
	 * @param tender
	 * @param ic
	 * @return
	 */
	BorrowTender experienceTenderSuccess(BorrowTender tender, InterestCalculator ic);

	/**
	 * 投标后立即生息，流转标
	 * 
	 * @param tender
	 */
	void immediateInterestAfterTender(BorrowTender tender);

	/**
	 * 投完标后立即还款，秒标、提前还息的几个
	 */
	void immediateRepayAfterTender(BorrowTender tender);

	/**
	 * 
	 */
	void immediateInviteAwardAfterTender();

	/**
	 * 计算借款手续费
	 * 
	 * @return 借款手续费
	 *//*已修改为根据用户投标记录单笔收取，该方法弃用
	double getManageFee();*/
	
	/**
	 * 计算借款管理费费率
	 * 
	 * @return
	 */
	double getBorrowManageFeeRate();

	/**
	 * 还款前校验
	 * 
	 * @param borrowRepayment
	 * @param account
	 */
	void validBeforeRepayment(BorrowRepayment borrowRepayment, Account account);

	/**
	 * 还款 处理借款人资金
	 * 
	 * @param repay
	 */
	void borrowRepayHandleBorrow(BorrowRepayment repay);

	/**
	 * 还款 处理投资人资金
	 * 
	 * @param repay
	 */
	void borrowRepayHandleTender(BorrowRepayment repay);
	
	/**
	 * 还款 处理借款人资金(提前还款)
	 * @param repay
	 */
	public void borrowPriorRepayHandleBorrow(BorrowRepayment repay);
	
	/**
	 * 还款 处理投资人资金(提前还款)
	 * @param repay
	 */
	public void borrowPriorRepayHandleTender(BorrowRepayment repay);
	
    /**
     * 代偿前校验
     * 
     * @param borrowRepayment
     */
    void validBeforeCompensate(BorrowRepayment borrowRepayment);
    
    /**
     * 满标复审不通过，处理加息券相关业务
     */
    void fullFailUpRateInerest();

    /**
     * 体验标处理加息券相关业务
     * @param tender
     */
	void handleExTenderAfterFullSuccess(BorrowTender tender);

	  /**
     * 体验标用
     */
	List<BorrowCollection> experienceCreateCollectionList(BorrowTender tender,
			InterestCalculator ic);

    /**
     * 体验标校验
     * @param model
     * @param user
     * @param userCache
     */
	void checkExperienceTender(BorrowModel model, User user, UserCache userCache);

	/**
	 * 处理投标中vip相关 - 等级与加息处理
	 * @param tender 投标
	 * @param tenderUser 投标用户
	 */
	void handleTenderVip(BorrowTender tender, User tenderUser);

}
